package org.jeecg.modules.demo.annualkeywork.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.jeecg.modules.demo.Constants;
import org.jeecg.modules.demo.annualkeywork.entity.KeyWorkDepartments;
import org.jeecg.modules.demo.annualkeywork.entity.TobedoneAnnualKeyWork;
import org.jeecg.modules.demo.annualkeywork.mapper.KeyWorkDepartmentsMapper;
import org.jeecg.modules.demo.annualkeywork.mapper.tobedoneAnnualKeyWorkMapper;
import org.jeecg.modules.demo.annualkeywork.service.ITobedoneAnnualKeyWorkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class TobedoneAnnualKeyWorkServiceImpl extends ServiceImpl<tobedoneAnnualKeyWorkMapper, TobedoneAnnualKeyWork> implements ITobedoneAnnualKeyWorkService {
    @Autowired
    private tobedoneAnnualKeyWorkMapper tobedoneAnnualKeyWorkMapper;
    @Autowired
    private KeyWorkDepartmentsMapper keyWorkDepartmentsMapper;
    //    根据配合部门选择待办的年度重点工作数据
    @Override
    public List<TobedoneAnnualKeyWork> SelectTobedoneAnnualKeyWorkListByOrgId(String orgId) {
        return tobedoneAnnualKeyWorkMapper.selectTobedoneAnnualKeyWorkListByOrgId(orgId);
    }
    //    插入年度重点工作,使用mapper的insertToAnnualKeyWork方法
    @Transactional(rollbackFor = Exception.class)
    @Override
    public void saveMain(TobedoneAnnualKeyWork tobedoneAnnualKeyWork, List<KeyWorkDepartments> keyWorkDepartmentsList) {
        tobedoneAnnualKeyWorkMapper.insertToAnnualKeyWork(tobedoneAnnualKeyWork);
        if(keyWorkDepartmentsList!=null && keyWorkDepartmentsList.size()>0) {
            for(KeyWorkDepartments entity:keyWorkDepartmentsList) {
                //外键设置
                entity.setTaskstatus(Constants.TODO);
                entity.setMainId(tobedoneAnnualKeyWork.getId());
                keyWorkDepartmentsMapper.insert(entity);
            }
        }
    }
    //    查询年度重点工作列表
    @Override
    public List<TobedoneAnnualKeyWork> selectAnnualKeyWorkList() {
        return tobedoneAnnualKeyWorkMapper.selectAnnualKeyWorkList();
    }
    //    根据子表id更新任务状态为已接收
    @Override
    public void updateByKeyWorkId(String id) {
        tobedoneAnnualKeyWorkMapper.updateByKeyWorkId(id);
    }
    //    记录待办年度重点工作的总数
    @Override
    public int TobedoneAnnualKeyWorkSum(String orgId) {
        return tobedoneAnnualKeyWorkMapper.TobedoneAnnualKeyWorkSum(orgId);
    }
    //    记录汇报年度重点工作的总数
    @Override
    public int ReportSumOfKeyWork(String orgId) {
        return tobedoneAnnualKeyWorkMapper.ReportSumOfKeyWork(orgId);
    }
    //    记录审批年度重点工作的总数
    @Override
    public int ApprovalSumOfKeyWork(String orgId) {
        return tobedoneAnnualKeyWorkMapper.ApprovalSumOfKeyWork(orgId);
    }
    //    记录年度重点工作的总数
    @Override
    public int KeyWorkSum(String orgId) {
        return tobedoneAnnualKeyWorkMapper.KeyWorkSum(orgId);
    }
}
